<template>
	<view class="dropdown">
		<u-picker :show="show" :columns="columns" keyName="day" @cancel="close" @confirm="handlePickerConfirm"
			style="z-index: 9999;"></u-picker>
		<view @click="togglePicker" class="dropdown_text">{{selectedValue}}</view>
		<view @click="togglePicker" class="dropdown_img"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				selectedValue: '年',
				value: null,
				columns: [
					[{
							day: '年',
							value: 2
						},
						{
							day: '月',
							value: 1
						},
						{
							day: '周',
							value: 0
						}
					]
				],
			}
		},
		methods: {
			togglePicker() {
				this.show = !this.show; // 点击显示/隐藏选择器
			},
			handlePickerConfirm(item) {
				console.log(item);
				this.selectedValue = item.value[0].day;
				this.show = false; // 确认后隐藏选择器
				this.value = item.value[0].value;
				this.$emit('myEvent', this.value)
			},
			close() {
				this.show = false;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.dropdown {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;

		.dropdown_text {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #bdbdbd;
		}

		.dropdown_img {
			width: 100%;
			height: 80%;
			background-image: url('../../static/images/home/向下1 拷贝 2.png');
			background-size: contain;
			background-repeat: no-repeat;
			background-position: 20rpx 0;
		}
	}
</style>